<!-- 
<template>
  <div>这是一个插件</div>
</template> -->


<template>
  <Teleport to="body" v-if="modalShow">
    <div>
      <div class="model-bck" @click="close ">
      </div>
      <div class="login-model">
        <div class="close">
          <img src="@/assets/img/close.png" alt="关闭" id="openis" @click="close">
        </div>
        <ul class="loginOptions">
          <li v-for="item in loginList" :key="item.id" :class="{ active: currentComop === item.id }"
            @click="setLoginType(item)">
            {{ item.name }}
          </li>
        </ul>
        <div class="login-content">
          <component @close="modalShow=false" :is="loginTypeDefault"></component>
        </div>
      </div>
    </div>

  </Teleport>
</template>
<script lang='ts' setup>
import codePW from '@/components/LoginModel/login/CodePW.vue'
import codeWX from '@/components/LoginModel/login/CodeWX.vue'
import codeSMS from '@/components/LoginModel/login/CodeSMS.vue'
import { ref,getCurrentInstance,ComponentInternalInstance ,inject ,onBeforeUnmount} from 'vue'
const { proxy } = getCurrentInstance() as ComponentInternalInstance
// const emit = defineEmits()
const modalShow = ref(true)


//监听子登录组件发送的登录成功  关闭登录框

// const showLoginDialog = inject('$showLoginDialog')

// 这里的关闭登录框事件  他不能获取到自定义插件的功能 只能手动操作Dom关闭清除他

//或者 在创建vue实例 挂载上去用

import { createApp } from 'vue';
import loginDialogPlugin from '@/plugin/loginDialogPlugin/index';
const app= createApp()
app.use(loginDialogPlugin)
const close = () => {
  modalShow.value = false
  
  app.config.globalProperties.$showLoginDialog(false)
  //手动清除这个容器
  // document.getElementById('loginDialog')?.remove()



  // modalShow.value = false
  // proxy.$showLoginDialog(false) 
}  //这里报错 chunk-544CHW4L.js?v=94dbef7e:1748 Uncaught TypeError: proxy.$showLoginDialog is not a function

const loginList = ref([
  { id: 1, name: '扫码登录', component: codeWX },
  { id: 2, name: '短信登录', component: codeSMS },
  { id: 3, name: '密码登录', component: codePW },
])
// 默认选中的
const currentComop = ref(1)
const loginTypeDefault = ref(codeWX)
const setLoginType = (item: any) => {
  currentComop.value = item.id
  loginTypeDefault.value = item.component
}
</script>
<style scoped lang='scss'>
.model-bck {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, .6);
  z-index: 999;
}

.login-model {
  z-index: 1000;
  width: 457px;
  min-height: 400px;
  border-radius: 40px 40px 40px 40px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 25px 39px 30px 40px;
  box-sizing: border-box;
}
.login-content{
  overflow: hidden;
  height: 300px;
}
.close {
  width: 100%;

  img {
    width: 17px;
    height: 17px;
    cursor: pointer;
    float: right;
  }
}


.loginOptions {
  width: 378px;
  height: 49px;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  margin-top: 25px;

  li {
    flex: 1;
    cursor: pointer;
    text-align: center;
    line-height: 49px;
    border-radius: 9px;
  }
}

.active {
  background-color: #c90000;
  color: #fff;
}
</style>
